package com.hospital.warehouse.drugstock.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hospital.util.DTO;
import com.hospital.warehouse.drugdicts.entity.Drugdicts;
import com.hospital.warehouse.drugdicts.service.DrugdictsService;
import com.hospital.warehouse.drugstock.entity.Drugstock;
import com.hospital.warehouse.drugstock.service.DrugstockService;
import com.hospital.warehouse.instock.entity.Instock;
import com.hospital.warehouse.instock.service.InstockService;
import com.hospital.warehouse.storehouse.entity.Storehouse;
import com.hospital.warehouse.storehouse.service.StorehouseService;
import com.hospital.warehouse.sys_user.entity.Sys_user;
import com.hospital.warehouse.sys_user.service.Sys_userService;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Mr. YR
 * @since 2020-04-21
 */
@Slf4j
@Controller
@RequestMapping("/warehouse/drugstock")
public class DrugstockController {
	@Autowired
	DrugdictsService drugdictsService;
	@Autowired
	Sys_userService sys_userService;
	@Autowired
	InstockService instockService;
	@Autowired
	StorehouseService storehouseService;
	@Autowired
	DrugstockService drugstockService;

	@RequestMapping("/page")
	public String page(Model model) {
		System.out.println("11111111111");
		// 添加药品集合，用于搜索下拉框
		List<Drugdicts> drugs = drugdictsService.list();
		model.addAttribute("drugs", drugs);
		// 添加用户集合，用于搜索下拉框
		List<Sys_user> users = sys_userService.list();
		model.addAttribute("users", users);

		// 添加入库单集合
		List<Instock> instocks = instockService.list();
		model.addAttribute("instocks", instocks);

		// 添加库房集合，用于搜索下拉框
		List<Storehouse> storehouses = storehouseService.list();
		model.addAttribute("storehouses", storehouses);

		// 添加库存集合，用于搜索选择
		List<Drugstock> drugstocks = drugstockService.list();
		model.addAttribute("drugstocks", drugstocks);

		// 前往主页面
		return "views/warehouse/drugstock.html";
	}

	@ResponseBody
	@RequestMapping("/paging")
	public DTO paging(Drugstock po, Integer page, Integer limit) {
		DTO dto = new DTO();
		try {
			dto = drugstockService.paging(po, page, limit);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setMsg("系统维护");
		}
		return dto;
	}

	@ResponseBody
	@RequestMapping("/queryByDrugId")
	public DTO queryByDrugId(Integer id) {
		DTO dto = new DTO();
		try {
			dto = drugstockService.queryByDrugId(id);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setMsg("系统维护");
		}
		return dto;
	}
}
